package com.yinhe.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.system.domain.YhSecuritywork;
import com.yinhe.system.service.IYhSecurityworkService;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.common.core.page.TableDataInfo;

/**
 * 保卫工作Controller
 * 
 * @author yinhe
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/system/securitywork")
public class YhSecurityworkController extends BaseController
{
    @Autowired
    private IYhSecurityworkService yhSecurityworkService;

    /**
     * 查询保卫工作列表
     */
    @PreAuthorize("@ss.hasPermi('system:securitywork:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhSecuritywork yhSecuritywork)
    {
        startPage();
        List<YhSecuritywork> list = yhSecurityworkService.selectYhSecurityworkList(yhSecuritywork);
        return getDataTable(list);
    }

    /**
     * 导出保卫工作列表
     */
    @PreAuthorize("@ss.hasPermi('system:securitywork:export')")
    @Log(title = "保卫工作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhSecuritywork yhSecuritywork)
    {
        List<YhSecuritywork> list = yhSecurityworkService.selectYhSecurityworkList(yhSecuritywork);
        ExcelUtil<YhSecuritywork> util = new ExcelUtil<YhSecuritywork>(YhSecuritywork.class);
        util.exportExcel(response, list, "保卫工作数据");
    }

    /**
     * 获取保卫工作详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:securitywork:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhSecurityworkService.selectYhSecurityworkById(id));
    }

    /**
     * 新增保卫工作
     */
    @PreAuthorize("@ss.hasPermi('system:securitywork:add')")
    @Log(title = "保卫工作", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhSecuritywork yhSecuritywork)
    {
        return toAjax(yhSecurityworkService.insertYhSecuritywork(yhSecuritywork));
    }

    /**
     * 修改保卫工作
     */
    @PreAuthorize("@ss.hasPermi('system:securitywork:edit')")
    @Log(title = "保卫工作", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhSecuritywork yhSecuritywork)
    {
        return toAjax(yhSecurityworkService.updateYhSecuritywork(yhSecuritywork));
    }

    /**
     * 删除保卫工作
     */
    @PreAuthorize("@ss.hasPermi('system:securitywork:remove')")
    @Log(title = "保卫工作", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhSecurityworkService.deleteYhSecurityworkByIds(ids));
    }
}
